<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>props的基本使用</title>
</head>

<body>
    <div id="test"></div>
    <div id="test1"></div>
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入prop-types,用于对组件标签属性进行限制 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    <script type="text/babel">
        //1 创建类式组件
        class Person extends React.Component {
            render() {
                const { name, age, sex } = this.props
                return (
                    <ul>
                        <li>姓名：{name}</li>
                        <li>性别：{sex}</li>
                        <li>年龄：{age + 1}</li>
                    </ul>
                )
            }
        }
        //进行类型和必要性
        Person.propTypes = {
            name: PropTypes.string.isRequired,
            sex: PropTypes.string,
            age: PropTypes.number,
            //函数
            speak:PropTypes.func
        }
        //默认值
        Person.defaultProps = {
            sex: '男',
            age: 0
        }
        //2 渲染组件到页面
        ReactDOM.render(<Person name='小李' sex="女" age={12} />, document.getElementById('test'))
        ReactDOM.render(<Person name='小李' sex="女"  />, document.getElementById('test1'))
    </script>
</body>

</html>